/**
 * 树
 */
(function($) {
	$.fn.jdTree = function() {
		var checkbox_colors = ['blue','green','red','yellow','pink','purple','gray','red2'];
		var tree = $(this);
		tree.addClass('jdtree');
		tree.children('h6').each(function(){
			var parent = $(this);
			var children=parent.next('ul');
			children.hide();
			$(this)
			.addClass("jdtree-parent")
			.click(function(){
				parent.toggleClass('expanded');
				children.slideToggle('fast');
			})
			.prepend("<span class='jdtree-arrow'>▼</span>")
			.addPressCls('mousedown')
			;
			if( $.browser.msie  ){
				$(this).find('.jdtree-arrow').css('font-size','1.1em');
				$(this).toggle(
					function(){$(this).find('.jdtree-arrow').html("▼");},
					function(){$(this).find('.jdtree-arrow').html("►");}
				);
			}
		});
		tree.children('ul').addClass("jdtree-children ");
		tree.find('ul.jdtree-children>li').each(function(i){
			$(this).addClass(checkbox_colors[i%checkbox_colors.length]);
		})
		.click(function(){
			tree.find(' ul.jdtree-children>li').removeClass('selected');
			$(this).addClass('selected');
		})
		.prepend('<span class="jdtree-checkbox"><span class="jdtree-checkbox-text">√</span></span>')
		;
		tree.find('ul.jdtree-children>li>.jdtree-checkbox')
		.addPressCls('mousedown')
		.addHoverCls('mouseover')
		.click(function(){
			$(this).parent().toggleClass('checked');
		})
		;
		
		tree.find('ul.jdtree-children>li>a').focus(function(){
			$(this).blur();
		});
		
		tree.children('h6').click();
		
		return this;
	};
	
})(jQuery);
